import { createApp,render,createVNode } from 'vue'
import './style.css'
import App from './App.vue'
import router from "./router/index";
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'

import loadingBar from './components/loadingBar.vue'
const Vnode = createVNode(loadingBar)
render(Vnode, document.body)
router.beforeEach((to, from, next) => {
    if (to.path === '/') {
        next()
    } else {
        const token = sessionStorage.getItem('token')
        if (!token) {
            next('/')
        } else {
            next()
            Vnode.component.exposed.startLoading()
        }
    }
})

router.afterEach((to, from) => {
    Vnode.component.exposed.endLoading()
})

const app = createApp(App)
app.use(ElementPlus)
app.use(router)
app.mount('#app')
